package com.x.example;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.x.example.page.PagesRouteHandler;
import com.x.example.page.WebActivity;
import com.x.uikit.router.IXRouteHandler;
import com.x.uikit.router.XRoute;
import com.x.uikit.router.XRouteManager;

public class RouterManager {
    Context mContext;
    Activity mActivity;
    XRouteManager mManager;

    private static class Holder {
        static RouterManager sInstance = new RouterManager();
    }

    public static RouterManager get() {
        return Holder.sInstance;
    }

    public void registerRouteHandler(IXRouteHandler handler) {
        if (mManager != null) {
            mManager.registerRouteHandler(handler);
        }
    }

    public void unregisterRouteHandler(IXRouteHandler handler) {
        if (mManager != null) {
            mManager.unregisterRouteHandler(handler);
        }
    }

    public void init(Application context) {
        mContext = context;
        mManager = new XRouteManager(context);
//        mManager.registerRouteHandler(new H5RouteHandler());
        context.registerActivityLifecycleCallbacks(new Application.ActivityLifecycleCallbacks() {
            @Override
            public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) {
                mActivity = activity;
            }

            @Override
            public void onActivityStarted(@NonNull Activity activity) {
                mActivity = activity;
            }

            @Override
            public void onActivityResumed(@NonNull Activity activity) {
                mActivity = activity;
            }

            @Override
            public void onActivityPaused(@NonNull Activity activity) {

            }

            @Override
            public void onActivityStopped(@NonNull Activity activity) {

            }

            @Override
            public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle outState) {

            }

            @Override
            public void onActivityDestroyed(@NonNull Activity activity) {

            }
        });
    }

}
